#include "WIT.h"

uint8_t wit_dmaBuffer[33];
uint8_t WIT_reset_data[3] = {0xFF, 0xAA, 0x52};
WIT_Data_t wit_data;

void WIT_Init(void)
{
    // 发送复位数据
    for(int i = 0; i < 3; i++) {
        DL_UART_transmitData(UART_WIT_INST, WIT_reset_data[i]);
        while(DL_UART_isBusy(UART_WIT_INST));
    }

    DL_DMA_setSrcAddr(DMA, DMA_WIT_CHAN_ID, (uint32_t)(&UART_WIT_INST->RXDATA));
    DL_DMA_setDestAddr(DMA, DMA_WIT_CHAN_ID, (uint32_t) &wit_dmaBuffer[0]);
    DL_DMA_setTransferSize(DMA, DMA_WIT_CHAN_ID, 32);
    DL_DMA_enableChannel(DMA, DMA_WIT_CHAN_ID);
    
    NVIC_EnableIRQ(UART_WIT_INST_INT_IRQN);
}


float Normal_Yaw(float Yaw_in)
{
    // 限幅-180 ~ 180
    if (Yaw_in > 180.0f) {
        Yaw_in -= 360.0f;
    } else if (Yaw_in < -180.0f) {
        Yaw_in += 360.0f;
    }
    return Yaw_in;
}